package service_k;

import mapper_k.BankMapper;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import pojo_k.HomeUserIncome;
import pojo_k.HomeUserPayout;
import util_k.SqlSessionFactoryUtils;

import java.util.List;

public class BankService {
    SqlSessionFactory factory = SqlSessionFactoryUtils.getSqlSessionFactory();

    //    查询余额
    public Float selectTotal() {
        //获取SqlSession
        SqlSession sqlSession = factory.openSession();

        //获取mapper
        BankMapper bankMapper = sqlSession.getMapper(BankMapper.class);

        //调用方法
        Float total = bankMapper.selectTotal();

        //释放资源
        sqlSession.close();

        //返回查到的数据
        return total;
    }

    //查询所有存款记录
    public List<HomeUserIncome> selectAllIncome(String homeuserName) {
        //获取SqlSession
        SqlSession sqlSession = factory.openSession();

        //获取mapper
        BankMapper bankMapper = sqlSession.getMapper(BankMapper.class);

        List<HomeUserIncome> homeUserIncomes = bankMapper.selectAllIncome(homeuserName);

        sqlSession.close();

        return homeUserIncomes;
    }

    //查询所有取款记录
    public List<HomeUserPayout> selectAllPayout(String homeuserName) {
        //获取SqlSession
        SqlSession sqlSession = factory.openSession();

        //获取mapper
        BankMapper bankMapper = sqlSession.getMapper(BankMapper.class);

        List<HomeUserPayout> homeUserPayouts = bankMapper.selectAllPayout(homeuserName);

        sqlSession.close();

        return homeUserPayouts;
    }

}
